package com.rrd.dw.mr.gzip.kafka;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.ucredit.babel.common.model.RecordType;
import com.ucredit.babel.common.model.third.baihang.BaihangFRAI0001Record;
import com.ucredit.babel.common.model.BaseModel;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper.Context;

import java.io.IOException;

/**
 * 百行黑名单新版本
 *
 * @author xj
 */
public class BaihangBlackListParse extends ParseBase {

    private Text val = new Text();
    private Text key = new Text();

    /**
     * 百行黑名单新版本
     *
     * @param model
     * @throws InterruptedException
     * @throws IOException
     */
    @Override
    public boolean parseJob(Context context, BaseModel<?> model, String successful) throws IOException, InterruptedException {
        BaihangFRAI0001Record obj = (BaihangFRAI0001Record) model;
        String dataStr = obj.getData();
        JSONObject data = JSON.parseObject(dataStr);
        StringBuilder sb = getBaseInfo(obj, successful);
        // 最高法被执行人名单 supremeCourtExecutedStatus
        sb.append(data.getString("supremeCourtExecutedStatus")).append(CRT001);
        // P2P逃废债名单 p2pEscapeDebtStatus
        sb.append(data.getString("p2pEscapeDebtStatus")).append(CRT001);
        // 近24月严重逾期信息 multiPartyLoanStatus
        sb.append(data.getString("multiPartyLoanStatus")).append(CRT001);
        // 近90天多头借贷信息 maxOverdueStatus
        sb.append(data.getString("maxOverdueStatus")).append(CRT001);
        StringBuilder txSb = getBaseInfo(obj);
        key.set(getKey());
        val.set((sb.toString() + txSb.toString()).replace("\n", " ").replace("\r", " "));
        context.write(key, val);
        return true;
    }

    @Override
    public String getTableName() {
        return "kafka_babel_baihang_blacklist_inc";
    }

    @Override
    public String getType() {
        return RecordType.BAIHANG_FRAI0001_RECORD.toString();
    }

    @Override
    public String getComment() {
        return "百行黑名单新版本";
    }
}
